import re


def check_mobile(value):
    if not re.match(r'1[3-9]\d', value):
        # 手机号不满足正则，抛出异常
        raise ValueError('手机号不满足格式')

    return value


# 对channel_id判断
def check_channel_id(value):
    # 判断是不是整数
    try:
        channel_id = int(value)
    except Exception:
        raise ValueError('传递的数据类型不对')
    else:
        if channel_id < 0:
            raise ValueError('id有误')
        # 推荐频道
        if channel_id == 0:
            return channel_id

        #判断是否在频道列表中
        from cache.channel import AllChannelCache
        ids = AllChannelCache.get_channel_ids
        if channel_id not in ids:
            raise ValueError('id 有误')

    return value
